package com.j.lemon.learn.flink.dataset;

import com.j.lemon.learn.flink.WordCount;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.tuple.Tuple2;

/**
 * 取最大最小值， 可以传多个字段列
 * @author lijunjun
 */
public class MinbyMaxbyOperator {
    public static void main(String[] args) throws Exception {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        DataSet<Tuple2<String,Integer>> dataSet = env.fromElements(
                new WordCount("zhangsan", 1),
                new WordCount("lisi", 2),
                new WordCount("lisi", 3))
                .map(new MapFunction<WordCount, Tuple2<String,Integer>>() {

                    @Override
                    public Tuple2<String,Integer> map(WordCount wordCount) throws Exception {
                        return new Tuple2<String,Integer>(wordCount.getWord(), wordCount.getCount());
                    }
                }).minBy(1,0);
        dataSet.print();


    }
}
